local Lua__sbxj = fk.CreateSkill {

  name = "Lua__sbxj",

}

local U = require "packages.utility.utility"

Fk:loadTranslationTable{
    
    ["Lua__sbxj"] = "石破天惊",
    ["#Lua__sbxjDeath"] = "石破天惊",
    ["$Lua__sbxj1"] = "斩尽杀绝！",
    ["$Lua__sbxj2"] = "AGAIN!",
    ["@@again"] = "再来！",
    ["#Lua__sbxjActive"] = "石破天惊：你可消耗100点蓄力点对一名其他角色造成等同于其体力值的伤害",
    [":Lua__sbxj"] = "蓄力技（0/100）出牌阶段，你可消耗100点蓄力点，对一名其他角色造成3点伤害，然后你随机获得一个技能名字含有“斩尽杀绝”的技能；场上有角色死亡时，若其本轮内成为过此技能的目标，你获得100点蓄力点。",
    ["@@sbxj_target-round"] = "石破天惊",
}


Lua__sbxj:addEffect("active", {
    anim_type = "offensive",
    prompt = "#Lua__sbxjActive",
    mute = true,
    can_use = function(self, player)
      return player:getMark("skill_charge") == 100
    end,
    card_filter = function() return false end,
    card_num = 0,
    target_num = 1,
    target_filter = function(self, player, to_select, selected)
        return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        room:setPlayerMark(target, "@@sbxj_target-round", 1)
        U.skillCharged(player, -100)
        if player:getMark("@@again") == 0 then
          player:broadcastSkillInvoke("Lua__sbxj", 1)
          room:notifySkillInvoked(player, Lua__sbxj.name, "offensive")
        else
          room:setPlayerMark(player, "@@again", 0)
          player:broadcastSkillInvoke("Lua__sbxj", 2)
          room:notifySkillInvoked(player, Lua__sbxj.name, "offensive")
        end
        -- 造成伤害
        room:damage({
            from = player,
            to = target,
            damage = 3,
            skillName = "Lua__sbxj"
        })
        local skills = {}
        for _, general_name in pairs(room.general_pile) do
          local general = Fk.generals[general_name]
          for _, skill_name in ipairs(general:getSkillNameList()) do
            local skill = Fk.skills[skill_name]
            if not player:hasSkill(skill, true) and (string.find(Fk:translate(skill.name), "斩") or string.find(Fk:translate(skill.name), "尽") or string.find(Fk:translate(skill.name), "杀")  or string.find(Fk:translate(skill.name), "绝"))  then
              table.insert(skills, skill.name)
            end
          end
        end
        if #skills > 0 then
          local skill_to_add = table.random(skills, 1)
          room:handleAddLoseSkills(player, skill_to_add, nil, true, false)
        end
    end,
})

Lua__sbxj:addEffect(fk.Death, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill("Lua__sbxj") and 
             target:getMark("@@sbxj_target-round") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
      -- 获得蓄力点
      local room = player.room
      room:setPlayerMark(player, "@@again", 1)
      U.skillCharged(player, 100)
  end,
})

Lua__sbxj:addLoseEffect(function(self, player)
    if not player:hasSkill("Lua__yujincaijue") then
    
      U.skillCharged(player, -0, -100)
    end
end)

Lua__sbxj:addAcquireEffect(function(self, player)
    if not player:hasSkill("Lua__yujincaijue") then
     U.skillCharged(player, 0, 100)
    end
end)

return Lua__sbxj